package com.ecoolex.discount.sales.core.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ecoolex.discount.sales.core.dao.UPlanCouponBatchDAO;
import com.ecoolex.discount.sales.entity.DiscountBrandWithBLOBs;
import com.ecoolex.discount.sales.entity.UPlanCouponBatch;
import com.ecoolex.discount.sales.pojo.QueryCouponBatchDTO;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.common.pojo.Sorting;
import com.ecoolex.framework.common.pojo.Sortings;

@Component
public class UPlanCouponBatchManager {
	@Autowired
	private UPlanCouponBatchDAO dao;

	public UPlanCouponBatch addBatch(UPlanCouponBatch entity) {
		dao.insert(entity);
		return entity;
	}

	public Pagination<DiscountBrandWithBLOBs> couponBatchList(QueryCouponBatchDTO query, Sorting[] sorts, Page page) {
		return Pagination.create(page, dao.count(query), () -> dao.query(query, Sortings.builder(sorts).toSql(), page));
	}

	public UPlanCouponBatch get(Long batchId) {
		return dao.selectByPrimaryKey(batchId);
	}
}